package com.ruoyi.web.controller.store.pan;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.PanOverflowReport;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.service.IPanOverflowReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 报损单/报溢单Controller
 *
 * @author wlmes
 * @date 2023-11-24
 */
@RestController
@RequestMapping("/overflow/report")
@Api(tags = "报损单/报溢单相关接口")
public class PanOverflowReportController extends BaseController {
    @Autowired
    private IPanOverflowReportService panOverflowReportService;


    /**
     * 查询报损单/报溢单列表
     */
    @GetMapping("/list")
    @ApiOperation("查询报损单/报溢单列表")
    public TableDataInfo list(PanOverflowReport panOverflowReport) {
        startPage();
        List<PanOverflowReport> list = panOverflowReportService.selectPanOverflowReportList(panOverflowReport);
        return getDataTable(list);
    }

    /**
     * 导出报损单/报溢单列表
     */
//    @PreAuthorize("@ss.hasPermi('system:report:export')")
    @Log(title = "报损单/报溢单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出报损单/报溢单列表")
    public AjaxResult export(PanOverflowReport panOverflowReport) {
        List<PanOverflowReport> list = panOverflowReportService.selectPanOverflowReportList(panOverflowReport);
        ExcelUtil<PanOverflowReport> util = new ExcelUtil<PanOverflowReport>(PanOverflowReport.class);
        return util.exportExcel(list, "report");
    }

    /**
     * 获取报损单/报溢单详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:report:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取报损单/报溢单详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(panOverflowReportService.selectPanOverflowReportById(id));
    }

    /**
     * 新增报损单/报溢单
     */
//    @PreAuthorize("@ss.hasPermi('system:report:add')")
    @Log(title = "报损单/报溢单", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增报损单/报溢单")
    @RepeatSubmit
    public AjaxResult add(@RequestBody PanOverflowReport panOverflowReport) {
        return toAjax(panOverflowReportService.insertPanOverflowReport(panOverflowReport));

    }

    /**
     * 修改报损单/报溢单
     */
//    @PreAuthorize("@ss.hasPermi('system:report:edit')")
    @Log(title = "报损单/报溢单", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改报损单/报溢单")
    @RepeatSubmit
    public AjaxResult edit(@RequestBody PanOverflowReport panOverflowReport) {
        return toAjax(panOverflowReportService.updatePanOverflowReport(panOverflowReport));
    }

    /**
     * 删除报损单/报溢单
     */
//    @PreAuthorize("@ss.hasPermi('system:report:remove')")
    @Log(title = "报损单/报溢单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除报损单/报溢单")
    @RepeatSubmit
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(panOverflowReportService.deletePanOverflowReportByIds(ids));
    }
}
